-- 27.lua
-- Created by zouyb Jun/26/2015
-- 酒鬼BUFF光效

return {
    onAppear = function(monster)    
	    -- 当前怪物的基类ID
		local baseClassId = monster:query("base_class_id");

		-- 计算当前酒鬼的个数	
        local openMonsterGrids = UIDungeonMgr:getCurLevel():getOpenMonsterGrids();
        local count = 0;
		local curMonsterGrid;
        for i = 1, #openMonsterGrids do
            local monsterGrid = openMonsterGrids[i];
            if monsterGrid.gridData.monster:query("base_class_id") == baseClassId then
				curMonsterGrid = monsterGrid;
                count = count + 1;
            end
        end

		if count == 1 then
			-- 酒鬼首次出现，播放“怪物出现”光效
			playMonsterFirstAppearEffect(curMonsterGrid);

			-- 屠夫和强盗播放“属性增益”光效
			for i = 1, #openMonsterGrids do
				local monsterGrid = openMonsterGrids[i];
				local tempBaseId = monsterGrid.gridData.monster:query("base_class_id");
                print("tempBaseId:"..tempBaseId)
				if tempBaseId == 24 or tempBaseId == 25 then
					playAddBuffEffect(monsterGrid, BUFF_TYPE_ATTACK);
				end
			end	
		end
    end,

    onDie = function(monster)    
	    -- 当前怪物的基类ID
		local baseClassId = monster:query("base_class_id");

		-- 计算当前酒鬼的个数	
        local openMonsterGrids = UIDungeonMgr:getCurLevel():getOpenMonsterGrids();
        local count = 0;
		local curMonsterGrid;
        for i = 1, #openMonsterGrids do
            local monsterGrid = openMonsterGrids[i];
            if monsterGrid.gridData.monster:query("base_class_id") == baseClassId then
				curMonsterGrid = monsterGrid;
                count = count + 1;
            end
        end

		if count == 0 then
			-- 场上只剩下一个酒鬼，在该酒鬼死亡时，屠夫和强盗播放“属性减益”光效	
			local openMonsterGrids = UIDungeonMgr:getCurLevel():getOpenMonsterGrids();
			for i = 1, #openMonsterGrids do
                local monsterGrid = openMonsterGrids[i];
				local tempBaseId = monsterGrid.gridData.monster:query("base_class_id")
				if tempBaseId == 24 or tempBaseId == 25 then
					playAddDeBuffEffect(monsterGrid, DEBUFF_TYPE_ATTACK);
				end
			end
		end
    end,
};